<?php
class UserModel extends Zend_Db_Table_Abstract{
    protected $_name = 'normaluser';
	protected $_primary = 'idNormalUser';
	protected $_itemPerPage = 10; 
    
    public function getAccountByUserName($user_name, $status){
        $db = Zend_Registry::get("connectDB");
        $mysql = $db->select()
                    ->from("account")
                    ->where("UserName = ?", $user_name);
        if(!empty($status)){
            $mysql->where("status = 1");
        }
        $result = $db->fetchRow($mysql);
        return $result;
    }
    
    public function getAccountByGoogleAccount($google_account, $status){
        $db = Zend_Registry::get("connectDB");
        $mysql = $db->select()
                    ->from("account")
                    ->where("google_account = ?", $google_account);
        $result = $db->fetchRow($mysql);
        if(!empty($status)){
            $mysql->where("status = 1");
        }
        return $result;
    }
    
    public function getAccountByFacebookAccount($face_account, $status){
        $db = Zend_Registry::get("connectDB");
        $mysql = $db->select()
                    ->from("account")
                    ->where("face_account = ?", $face_account);
        $result = $db->fetchRow($mysql);
        if(!empty($status)){
            $mysql->where("status = 1");
        }
        return $result;
    }
    
    public function insertAccount($data){
        $db = Zend_Registry::get("connectDB");
        $id_account = $db->insert("account", $data);
        return $db->lastInsertId();
    }
    
    public function updatePassAccount($pass, $id){
        $db = Zend_Registry::get("connectDB");
        $db->update("account", array("Password"=>$pass), "idAccount=".$id);
    }
    
    public function checkAccount($user_name, $password){
        $db = Zend_Registry::get("connectDB");
        $mysql = $db->select()
                    ->from("account")
                    ->where("UserName = ?", $user_name)
                    ->where("Password = ?", md5($password))
                    ->where("status = 1");
        $result = $db->fetchRow($mysql);
        return $result;
    }
    
    public function getUserInfoByID($params){
        $db = Zend_Registry::get("connectDB");
        $mysql = $db->select()
                    ->from(array("a"=>"account"))
                    ->join(array("u"=>"normaluser"), "u.idNormalUser=a.idAccount")
                    ->where("a.idAccount = ?", $params['user_id']);
                    
        if(!empty($params['status'])){
            $mysql->where("status = 1");
        }
        $result = $db->fetchRow($mysql);
        return $result;
    }
}